package com.sodaopen.crm.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.sodaopen.crm.common.interceptor.JwtInterceptor;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    //解决跨域问题
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
    
    //添加拦截器
  	public void addInterceptors(InterceptorRegistry registry) {
  		registry.addInterceptor(new JwtInterceptor())  //Jwt认证拦截器
  				.addPathPatterns("/**")
  				.excludePathPatterns("/login")
  				.excludePathPatterns("/webjars/**")
  				.excludePathPatterns("/swagger-resources/**")
  				.excludePathPatterns("/swagger-ui.html/**");
  	}
    

}
